var treedata = [{
    "id": 1,
    "text": "Folder1",
    "iconCls": "icon-ok",
    "children": [{
        "id": 2,
        "text": "File1",
        "checked": true
    }, {
        "id": 3,
        "text": "Folder2",
        "state": "open",
        "children": [{
            "id": 4,
            "text": "File3",
            "attributes": {
                "p1": "value1",
                "p2": "value2"
            },
            "checked": true,
            "iconCls": "icon-reload"
        }, {
            "id": 8,
            "text": "Async Folder",
            "state": "closed"
        }]
    }]
}, {
    "text": "Languages",
    "state": "closed",
    "children": [{
        "id": "j1",
        "text": "Java"
    }, {
        "id": "j2",
        "text": "C#"
    }]
}];
var datagrid_data = {
    "total": 28,
    "rows": [{
        "productid": "FI-SW-01",
        "unitcost": 10.00,
        "status": "P",
        "listprice": 36.50,
        "attr1": "Large",
        "itemid": "EST-1"
    }, {
        "productid": "K9-DL-01",
        "unitcost": 12.00,
        "status": "P",
        "listprice": 18.50,
        "attr1": "Spotted Adult Female",
        "itemid": "EST-10"
    }, {
        "productid": "RP-SN-01",
        "unitcost": 12.00,
        "status": "P",
        "listprice": 28.50,
        "attr1": "Venomless",
        "itemid": "EST-11"
    }, {
        "productid": "RP-SN-01",
        "unitcost": 12.00,
        "status": "P",
        "listprice": 26.50,
        "attr1": "Rattleless",
        "itemid": "EST-12"
    }, {
        "productid": "RP-LI-02",
        "unitcost": 12.00,
        "status": "P",
        "listprice": 35.50,
        "attr1": "Green Adult",
        "itemid": "EST-13"
    }, {
        "productid": "FL-DSH-01",
        "unitcost": 12.00,
        "status": "P",
        "listprice": 158.50,
        "attr1": "Tailless",
        "itemid": "EST-14"
    }, {
        "productid": "FL-DSH-01",
        "unitcost": 12.00,
        "status": "P",
        "listprice": 83.50,
        "attr1": "With tail",
        "itemid": "EST-15"
    }, {
        "productid": "FL-DLH-02",
        "unitcost": 12.00,
        "status": "P",
        "listprice": 63.50,
        "attr1": "Adult Female",
        "itemid": "EST-16"
    }, {
        "productid": "FL-DLH-02",
        "unitcost": 12.00,
        "status": "P",
        "listprice": 89.50,
        "attr1": "Adult Male",
        "itemid": "EST-17"
    }, {
        "productid": "AV-CB-01",
        "unitcost": 92.00,
        "status": "P",
        "listprice": 63.50,
        "attr1": "Adult Male",
        "itemid": "EST-18"
    }]
}


var MainIndex = {
    Objects: {
        treeData: []
    },
    Init: function() {
        $(window).bind("resize", function() {
            // var tree = $("#leftree");
            // var height =$(window).outerHeight()-$(".lefttop").outerHeight()-$(".topleft").outerHeight();
            // alert(height)
            // tree.height();

        });
        MainIndex.InitTree();
        MainIndex.InitGrid();
        $(".select1").uedSelect({
            width: 120
        });
    },
    InitTree: function() {

        var tree = $("#leftree");
        tree.tree({
            url: "data/tree_data.json",
            data: treedata
        });


    },
    InitGrid: function() {
        var grid = $("#grid");
        grid.datagrid({
            // url: 'data/datagrid_data.json',
            title: 'DataGrid',
            data: datagrid_data,
            // width: 700,
            height: 300,
            fitColumns: true,
            nowrap: false,
            columns: [
                [{
                    field: 'code',
                    title: 'Item ID',
                    width: 80
                }, {
                    field: 'productid',
                    title: 'Product ID',
                    width: 120
                }, {
                    field: 'listprice',
                    title: 'List Price',
                    width: 80,
                    align: 'right',
                    styler: function(value, row, index) {
                        if (value < 20) {
                            return 'background-color:#ffee00;color:red;';
                        }
                    }
                }, {
                    field: 'unitcost',
                    title: 'Unit Cost',
                    width: 80,
                    align: 'right'
                }, {
                    field: 'attr1',
                    title: 'Attribute',
                    width: 250
                }, {
                    field: 'status',
                    title: 'Status',
                    width: 60,
                    align: 'center'
                }]
            ],
            rowStyler: function(index, row, css) {
                if (row.listprice > 80) {
                    return 'background-color:#6293BB;color:#fff;font-weight:bold;';
                }
            }
        });
    },
    Resize: function() {

    }
};
jQuery(function($) {
    MainIndex.Init();
});
